package com.lcc;

import com.lcc.dao.ProvinceMappper;
import com.lcc.dto.ProvincePO;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

/**
 * @author lincc
 * @version 1.0 2021/8/26
 */
public class TestProvince {
    public static void main(String[] args) throws IOException {
        //1.加载SqlMapConfig.xml
        InputStream in = Resources.getResourceAsStream("mybatis-config.xml");

        //2.创建SqlSessionFactory工厂
        SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
        SqlSessionFactory factory = builder.build(in);

        //3.创建SqlSession
        SqlSession sqlSession = factory.openSession();

        //4.生成Dao接口代理对象
        ProvinceMappper provinceMappper = sqlSession.getMapper(ProvinceMappper.class);

        //5.执行Dao接口方法
        List<ProvincePO> list = provinceMappper.listAll();

        list.forEach(System.out::println);

        //6.释放资源
        sqlSession.close();
        in.close();
    }
}
